import os
from dish_manager import manage_dishes_interaction, view_all_dishes
from recommender import get_recommendations_interaction, filter_dishes_by_criteria_interaction
from storage_manager import load_all_dishes_from_file, save_all_dishes_to_file


def display_main_menu():
    """显示主菜单选项"""
    print("\n=== 食堂菜品选择困难拯救器 ===")
    print("1. 添加/管理菜品信息")
    print("2. 今日菜品推荐")
    print("3. 查看所有菜品")
    print("4. 按条件筛选菜品")
    print("5. 退出程序")


def main_loop():
    """主程序循环"""
    # 确保data目录存在
    if not os.path.exists("data"):
        os.makedirs("data")

    # 加载所有菜品数据
    all_dishes = load_all_dishes_from_file()

    while True:
        display_main_menu()
        choice = input("请选择操作 (1-5): ").strip()

        if choice == '1':
            # 管理菜品
            updated_dishes = manage_dishes_interaction(all_dishes)
            if updated_dishes:
                all_dishes = updated_dishes
                save_all_dishes_to_file(all_dishes)

        elif choice == '2':
            # 今日菜品推荐
            get_recommendations_interaction(all_dishes)

        elif choice == '3':
            # 查看所有菜品
            view_all_dishes(all_dishes)

        elif choice == '4':
            # 按条件筛选菜品
            filter_dishes_by_criteria_interaction(all_dishes)

        elif choice == '5':
            # 退出程序
            print("感谢使用食堂菜品推荐系统，再见！")
            break

        else:
            print("无效选择，请输入1-5之间的数字！")


if __name__ == "__main__":
    main_loop()